package com.ars.common.dao;

import com.ars.common.beans.Active.Active;
import com.ars.common.utils.DBUtil;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.TreeMap;

public class FindActiveInformation {
    public static TreeMap <Integer, Active> findActive() throws SQLException {

        TreeMap<Integer, Active> Tmap = new TreeMap<Integer, Active>();

        String sql = "select a.id,a.`name`,a.creatorID,a.beginTime,a.endTime,a.type,u.`name` as Creator\n" +
                "FROM active a\n" +
                "left JOIN user u ON a.creatorID = u.userID;";
        PreparedStatement ps = DBUtil.getConnection().prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next())
        {
            Active active = new Active();
            active.setId(rs.getInt("id"));
            active.setName(rs.getString("name"));
            active.setCreatorID(rs.getString("creatorID"));
            active.setBeginTime(rs.getString("beginTime"));
            active.setEndTime(rs.getString("endTime"));
            active.setType(rs.getString("type"));
            active.setCreator(rs.getString("Creator"));
            Tmap.put(active.getId(),active);

//            System.out.println(active.toString());
        }
        return Tmap;
    }
}
